# file:: $Name$
# author::  $Author$
# version:: $Revision$
# date:: $Date$
#
# This source code copyright (C) 2006 by Ralph M. Churchill
# All rights reserved.
#
# Released under the terms of the GNU General Public License
# See LICENSE file for additional information.

require 'engine/command'

class Emote < Command
    def initialize(char)
        super(char,'emote','emote <verb phrase>',
              'Perform a superfluous action.')
    end
    def execute(args)
        raise UsageException if args.empty?
        GameEngine.instance.do_action(Action.new(:vision,self.executor.room,
         {:sight => "#{TelnetCommands::BOLD+self.executor.name+TelnetCommands::RESET} #{args.join(' ')+TelnetCommands::EOL}"}))
    end
end

class Help < Command
    def initialize(char)
        super(char,'help','help [command]',
        'Print the list of commands or get help on a specific command.')
    end
    def execute(args)
        helpon = args.join(' ') unless args.empty?
        if helpon and (not helpon.empty?) then
            if cmd = self.executor.commands.find{|c| c.name==helpon}
                msg = cmd.usage+TelnetCommands::EOL+cmd.description
            else
                msg = "No help available for \"#{helpon}\""
            end
        else
            msg=<<EOF
#{TelnetCommands::BOLD}/#{TelnetCommands::RESET} - repeat the last command
#{TelnetCommands::BOLD}'#{TelnetCommands::RESET} - alias for "say"
#{TelnetCommands::BOLD}me#{TelnetCommands::RESET} - alias for "emote"
EOF
            msg += self.executor.commands.collect{
                |c| "#{TelnetCommands::BOLD+c.name+TelnetCommands::RESET} - #{c.description}"}.join(TelnetCommands::EOL)
        end
        self.inform(msg)
    end
end

class Inventory < Command
    def initialize(char)
        super(char,'inv','inv',
        'Print Inventory')
    end
    def execute(args)
        msg = "
--------------------------------------------------------------------------------
 #{TelnetCommands::BOLD}Your Inventory#{TelnetCommands::RESET}
--------------------------------------------------------------------------------
"
self.executor.items.each do |item|
    msg += "#{item.name+TelnetCommands::EOL}"
end
    msg += "
--------------------------------------------------------------------------------
"
        self.inform(msg)
    end
end
